/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Calendar;
import java.util.UUID;

/**
 * <p>Project: jse2204 - Str3
 * <p>Powered by webrx On 2022-09-13 16:14:44
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Str3 {
    public static void main(String[] args) {
        String str = "hello java java 19 demo.";
        //判断
        System.out.println(str.contains("java"));
        System.out.println("abc.jpg".endsWith(".jpg"));
        System.out.println("Hello.java".startsWith("Hello"));
        System.out.println("hello".equals("Hello"));
        System.out.println("hello".equalsIgnoreCase("Hello"));
        System.out.println("hello".length()>3);

        //转换
        System.out.println("hello JAVA".toLowerCase());
        System.out.println("hello JAVA".toUpperCase());
        System.out.println("*".repeat(35));

        //索引
        System.out.println(str.indexOf("java"));//6
        System.out.println(str.lastIndexOf("java"));//11
        System.out.println(str.indexOf("python")); //-1
        System.out.println("星期"+"日一二三四五六".charAt(Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1));

        //截取子串
        //String pic = "d:\\user\\uploads\\20220913162633.jpg
        //获取扩展名
        System.out.println("hello".substring(2));//获取2开始到结尾的子串，并返回
        System.out.println("hello".substring(2,3));
        String pic = "d:\\user\\uploads\\20220913162633.jpg";
        System.out.println(pic.substring(pic.lastIndexOf("."))); //.jpg

        //获取文件名
        System.out.println(pic.substring(pic.lastIndexOf("\\")+1)); //20220913162633.jpg

        //获取文件路径
        System.out.println(pic.substring(0,pic.lastIndexOf("\\")));

        //修改文件名称 为 d:\\user\\uploads\\1000.jpg
        String uid = UUID.randomUUID().toString().toLowerCase();
        System.out.println(uid);
        System.out.println(pic.substring(0,pic.lastIndexOf("\\")) + "\\" + uid + pic.substring(pic.lastIndexOf(".")));

        //替换，删除
        System.out.println("hello,java,java 19".replace("java","python"));
        System.out.println("hello,java,java 19".replace("java",""));

        //请删除字符串中的所有数字。 、\\d 是正则表达式，代表数字 replaceAll() 此替换方法是支持正则表达式的。
        System.out.println("hello123java8myjava12".replace("\\d",""));
        System.out.println("hello123java8myjava12".replaceAll("\\d",""));


        //字符串倒序
        String s = "java123";
        System.out.println(s);
        System.out.println(new StringBuffer(s).reverse());

        String t = "";
        for(int i=0;i<s.length();i++){
            t = s.charAt(i) + t;
        }
        System.out.println(t);
    }
}
